// 统一页面路由处理
import router from './router'
import {getToken} from "./utils/auth";
import setting from "./settings";
const whiteList = ['/login'] // no redirect whitelist
router.beforeEach(async (to, from, next) => {
  document.title = to.meta.title
  const hasToken = getToken()

  if(setting.NEED_LOGIN && import.meta.env.DEV){
    if (hasToken) { // 有token直接跳转
      next()
    } else { // 没token的情况
      if (whiteList.indexOf(to.path) !== -1) {
        // 在白名单内的直接跳转
        next()
      } else {
        // 不在白名单内的跳转到登录页
        next(`/login?redirect=${to.path}`)
      }
    }
  }else {
    next()
  }

})

router.afterEach(() => {})
